﻿/*!
 CLEditor XHTML Plugin v1.0.1
 http://premiumsoftware.net/cleditor
 requires CLEditor v1.3.0 or later
 
 Copyright 2010, Chris Landowski, Premium Software, LLC
 Dual licensed under the MIT or GPL Version 2 licenses.
 Based on John Resig's HTML Parser Project (ejohn.org)
 http://ejohn.org/files/htmlparser.js
 Original code by Erik Arvidsson, Mozilla Public License
 http://erik.eae.net/simplehtmlparser/simplehtmlparser.js
*/
(function(n){var t=n.cleditor.defaultOptions.updateTextArea;n.cleditor.defaultOptions.updateTextArea=function(i){return t&&(i=t(i)),n.cleditor.convertHTMLtoXHTML(i)},n.cleditor.convertHTMLtoXHTML=function(n){function f(n){for(var i={},r=n.split(","),t=0;t<r.length;t++)i[r[t]]=!0;return i}function k(n,r,u,f){var o,s;if(r=r.toLowerCase(),v[r])while(t.last()&&y[t.last()])e("",t.last());for(p[r]&&t.last()==r&&e("",r),f=a[r]||!!f,f||t.push(r),o=[],u.replace(l,function(n,t){var i=arguments[2]?arguments[2]:arguments[3]?arguments[3]:arguments[4]?arguments[4]:w[t]?t:"";o.push({name:t,escaped:i.replace(/(^|[^\\])"/g,'$1\\"')})}),i+="<"+r,s=0;s<o.length;s++)i+=" "+o[s].name+'="'+o[s].escaped+'"';i+=(f?"/":"")+">"}function e(n,r){var u,f;if(r){for(r=r.toLowerCase(),u=t.length-1;u>=0;u--)if(t[u]==r)break}else u=0;if(u>=0){for(f=t.length-1;f>=u;f--)i+="<\/"+t[f]+">";t.length=u}}function c(n,t){i=i.replace(n,t)}var s=/^<(\w+)((?:\s+[\w+-]+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/,h=/^<\/(\w+)[^>]*>/,l=/([\w+-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g,a=f("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed"),v=f("address,applet,blockquote,button,center,dd,del,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul"),y=f("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"),p=f("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr"),w=f("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),b=f("script,style"),t=[],r,u,o,i;for(t.last=function(){return this[this.length-1]},o=n,i="";n;){if(t.last()&&b[t.last()]?(n=n.replace(new RegExp("(.*)<\/"+t.last()+"[^>]*>"),function(n,t){return t=t.replace(/<!--(.*?)-->/g,"$1").replace(/<!\[CDATA\[(.*?)]]>/g,"$1"),i+=t,""}),e("",t.last())):n.indexOf("<!--")==0?(r=n.indexOf("-->"),r>=0&&(i+=n.substring(0,r+3),n=n.substring(r+3))):n.indexOf("<\/")==0?(u=n.match(h),u&&(n=n.substring(u[0].length),u[0].replace(h,e))):n.indexOf("<")==0?(u=n.match(s),u&&(n=n.substring(u[0].length),u[0].replace(s,k))):(r=n.indexOf("<"),i+=r<0?n:n.substring(0,r),n=r<0?"":n.substring(r)),n==o)throw"Parse Error: "+n;o=n}return e(),c(/<b>(.*?)<\/b>/g,"<strong>$1<\/strong>"),c(/<i>(.*?)<\/i>/g,"<em>$1<\/em>"),i}})(jQuery);